const app = new Vue({
    el: '#loginBox',
    data: function () {
        return {
            account: {
                username: '',
                password: '',
                type: ''
            }
        }
    },
    methods: {
        login: function () {
            if (this.account.username === '') {
                this.$message.warning('用户名不能为空！');
                return;
            }
            if (this.account.password === '') {
                this.$message.warning('密码不能为空！');
                return;
            }

            let that = this;
            axios.post('/login', that.account).then(
                function (response) {
                    console.log(response);
                    let code = response.data.code;
                    if (code === 200) {
                        let isPerfect = response.data.data.isPerfect;
                        let type = response.data.data.type;
                        let token = response.data.data.token
                        window.localStorage.setItem('userToken', token);
                        if (isPerfect === '0') {
                            location.href = '../view/perfect_info.html?type=' + type;
                        } else if (isPerfect === '1') {
                            if (type === '1') {
                                location.href = '../view/manufacturer/home.html';
                            } else if (type === '2') {
                                location.href = '../view/seller/home.html';
                            } else if (type === '3') {
                                location.href = '../view/supervision/home.html';
                            }
                        }
                    } else if (code === 1001) {
                        that.$message.warning('用户名或密码不能为空！');
                    } else if (code === 1003) {
                        that.$message.error('用户名或密码有误，请重新尝试！');
                    }
                }, function (err) {
                    console.log(err);
                }
            )
        }
    },
});